//
//  BSTabBar.m
//  sister
//
//  Created by 周冰烽 on 2017/2/8.
//  Copyright © 2017年 周冰烽. All rights reserved.
//

#import "BSTabBar.h"

@interface BSTabBar()
/** 发布按钮 */
@property(nonatomic,strong)UIButton *publishButton;

@end

@implementation BSTabBar

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
        UIButton *publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateSelected];
        [self addSubview:publishButton];
        self.publishButton = publishButton;
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    //设置发布按钮的frame
    _publishButton.bounds = CGRectMake(0, 0, _publishButton.currentBackgroundImage.size.width, _publishButton.currentBackgroundImage.size.height);
    _publishButton.center = CGPointMake(self.width * 0.5, self.height * 0.5);
    [self addSubview:_publishButton];
    CGFloat buttonY = 0;
    CGFloat buttonW = self.width / 5;
    CGFloat buttonH = self.height;
    NSInteger index = 0;
    //设置其他UITabBarButton的frame
    for (UIView *button in self.subviews) {
        if (![button isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            continue;
        }
        CGFloat buttonX = buttonW * ((index>1)?(index+1):index);
        button.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
        index++;
    }
    
    
    
}

@end
